% decimal number transform to a binary vector
% This function can transform a decimal number(positive/negative) to a
% binary vector
function remainder_bin = dec_to_binary(dec, digits)

remainder_bin = [];
temp_dec = abs(dec);
% whatever number, first should transform to binary represatation
for i = 1:digits
    remainder_bin = [rem(temp_dec, 2), remainder_bin];
    temp_dec = floor(temp_dec / 2);
end
% for positive decimal number transform to binary directly
if dec > 0
    return
else
    % for negative number transform to binary in complement
    % radix-minus-one complement
    remainder_bin = ~remainder_bin;
    % complement
    remainder_bin(1) = 0;
    remainder_bin = dec_to_binary(binary_to_dec(remainder_bin) + 1, digits);
    remainder_bin(1) = 1;
end

end
